<template>
	<view>

		<!-- 轮播图 -->
		<view class="top1 " v-if="data.imgs!=null">
			<swiper circular :interval="3000" :current="current" :duration="400" @change="change"
				style="width: 100%;height: 750rpx;">
				<swiper-item v-for="(item ,index) in data.imgs.split(',')" :key="index"
					style="width: 100%;height: 750rpx;">
					<image :src="item" style="width: 100%;height: 750rpx;" @click="swiperClick(item)">
					</image>
				</swiper-item>
			</swiper>
		</view>

		<view class=" bg-white  padding-sm">
			<view class="font-34rpx" style="display: flex;  justify-content: space-between;">
				<view>{{data.title}}</view>
				<view>
					<button open-type="share" class="login-btn cu-btn block bg-orange"
						style="font-size: 26rpx;"><uni-icons type="redo-filled" color="#fff" size="20"></uni-icons>
						分享</button>
				</view>
			</view>
			<view class="margin-top-xs " style="color: #999;">
			</view>

			<view class="margin-top-sm" style="display: flex;  justify-content: space-between;">
				<view>{{data.date}}</view>
				<view>参与人数:{{data.number}}人</view>
			</view>
		</view>

		<view class=" bg-white  padding-sm margin-top-sm" @click="yuanzixiangqing">
			<view>相关院子</view>
			<roomMJ v-if="yuanzi!=null" :data="yuanzi" class="margin-top-xs"></roomMJ>
		</view>

		<view class=" bg-white  padding-sm margin-top-sm">
			<view>图文详情</view>
			<view class="margin-top-xs " v-if="yuanziMarkdownIsOk=='loading'">
				<uni-load-more :status="yuanziMarkdownIsOk"></uni-load-more>
			</view>

			<view class="margin-top-xs" v-if="yuanziMarkdownIsOk!='loading'" v-html="data.json">

			</view>

		</view>
	</view>
</template>

<script>
	import {
		getJson
	} from "@/api/system/user.js"
	import {
		listByDistance10
	} from "@/api/shop/shopconfig/ShopConfigManagementApi.js"
	import {
		getpreviouseventsbyid
	} from '@/api/shop/previousevents/ShopPreviousEventsManagementApi'
	import {
		isNull
	} from "@/utils/validate"
	export default {
		data() {
			return {
				location: null,
				yuanziMarkdownIsOk: "loading",
				yuanzi: null,
				data: {
					id: null
				},
				current: 0,

			}
		},
		onLoad(e) {
			this.data.id = decodeURIComponent(e.id);
			this.init()
		},
		methods: {
			onShareAppMessage: function(res) {
				// 返回分享的内容
				return {
					title: this.data.title,
					url: "/pages/common/wangqihuodong/wangqihuodong?id=" + this.data.id,
					imageUrl: this.data.imgs.split(',')[0] // 自定义分享图标，可选
				}
			},
			init() {
				this.location = this.$storage.getItem("location")
				this.getpreviouseventsbyid()
			},

			async getpreviouseventsbyid() {
				let {
					data
				} = await getpreviouseventsbyid(this.data)
				this.data = data
				this.getJson()
				this.listByDistance10(data.tenantId)

			},

			async listByDistance10(id) {
				let location = this.$storage.getItem("location")
				let q = {
					id: id,
				}
				if (!isNull(this.location)) {
					// await this.getLocation()
					// location = this.$storage.getItem("location")
					q.lat = this.location.latitude
					q.lon = this.location.longitude
				}
				let {
					data
				} = await listByDistance10(q)
				data[0].image = data[0].image.split(",")
				this.yuanzi = data[0]

				this.yuanzi.cangdiList = JSON.parse(this.yuanzi.cangdiList)
				let ads = 10000
				for (let s of this.yuanzi.cangdiList) {
					if (parseFloat(s.price) < ads) {
						ads = parseFloat(s.price)
					}
				}
				this.yuanzi.miniPrice = ads

			},
			async getJson() {
				let {
					data
				} = await getJson(this.data.json)

				this.yuanziMarkdownIsOk = "noMore"
				let newStr = data.replace("<img src", "<img style='width:100%' src");

				this.data.json = newStr
			},
			change(e) {
				this.current = e.detail.current
			},
			/**
			 * 院子详情
			 * @param {Object} data
			 */
			yuanzixiangqing() {
				uni.navigateTo({
					url: "/pages/common/yuanzixiangqing/yuanzixiangqing?id=" + this.yuanzi.id
				})
			},
		}
	}
</script>

<style>

</style>